"""PDE solvers"""

import numpy as N

def trisys(a, d, c, b):
    """Tridiagonal equations solver
    A: the subdiagonal of the coeffective matrix
    D: the main diagonal of the coeffective matrix
    C: the superdiagonal of the coeffective matrix
    B: the constant vector of the linear system
    """
    n = len(b)
    for i in range(1, n):
        mult = a[i - 1] / d[i - 1]
        d[i] = d[i] - mult * c[i - 1]
        b[i] = b[i] - mult * b[i - 1]
    X = range(n)
    X[-1] = b[-1] / d[-1]
    for i in range(n-2, -1, -1):
        X[i] = (b[i] - c[i] * X[i + 1]) / d[i]
    return X
    
    